package net.didactylos.helpline.action;


import org.hibernate.*;

import net.didactylos.helpline.data.*;
import net.didactylos.helpline.stripes.bean.HelplineActionBean;
import net.didactylos.helpline.stripes.security.*;
import net.sourceforge.stripes.action.*;
import net.sourceforge.stripes.validation.*;

public class EditRoleAction extends HelplineActionBean
{
    
	@ValidateNestedProperties({
        @Validate(field="name", required=true),
        @Validate(field="capabilities", required=true)
    })
    private Role role;
	
	public Role getRole()
	{
		return role;
	}

	public void setRole(Role role)
	{
		this.role = role;
	}

	@DontValidate
	@DefaultHandler
	@Secured(Capabilities.SIGN_IN)
	public Resolution view()
	{
		return new ForwardResolution("editRole.jspx");
	}

	@Secured(Capabilities.SIGN_IN)
	public Resolution editRole()
	{
		Session session = getContext().getSession();
		session.update(role);
        
        getContext().getMessages().add(new LocalizableMessage("editRoleMessage", role.getName()));
		return new RedirectResolution(UsersAction.class);
	}

}
